package com.lugea.common.json;

import java.io.IOException;

import org.joda.time.LocalDate;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;

/**
 * @author enluw
 * @date 2020-01-27
 * @描述 LocalDate反序列化
 */
public class LocalDateStdScalarDeserializer extends StdScalarDeserializer<LocalDate> {

    private static final long serialVersionUID = -1836098541774846880L;

    protected LocalDateStdScalarDeserializer() {
        super(LocalDate.class);
    }

    @Override
    public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
            throws IOException, JsonProcessingException {
        JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
        return LocalDate.parse(jsonNode.asText());
    }
}
